<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
     	<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.validate.min.js"></script>
     	<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.ididenify.js"></script>
	</head>
	<body>
		<div class="container">
			<div class="row">
				<div class="col-md-4 col-md-offset-4">
					<div class="panel panel-default input_login">
						<div class="panel-heading">
							<h3 class="panel-title text-center" style="font-size: 20px;font-weight: bold;">代理注册</h3>
						</div>
						<div class="panel-body">
							<!--tips-->
							<p class="text-center">
						    	<button type="button"
			                    id="showRules"
			                    class="btn btn-danger"
			                    data-toggle="popover"
			                    data-placement="bottom"
			                    data-html="true"
			                    title="代理规则"
			                    data-content="
			                    <p>注册时没填写推荐码，则默认成为一级代理；</p>
			                    <p>注册时填写了推荐码，则成为推荐人的下级代理；</p>
			                    <p>注册成为代理后需要通过管理审核后才能登录。</p>">
			                		查看规则
			            		</button>
						    </p>
							
							<form role="form" id="signupForm">
	                            <fieldset>
	                            	<div class="form-group">
	                                    <input class="form-control" placeholder="请输入游戏ID" name="user_id" id="user_id" type="text"/>
	                                </div>
	                                <div class="form-group">
	                                    <input class="form-control" placeholder="请输入手机号" name="tel" id="tel" type="text" autofocus="autofocus"/>
	                                </div>
	                                <div class="form-group">
	                                    <input class="form-control" placeholder="请输入密码" name="password" id="password" type="password"/>
	                                </div>
	                                <div class="form-group">
	                                    <input class="form-control" placeholder="{:L(GAME_LOGIN_REFER)}" name="refer" id="refer" type="text"/>
	                                </div>
	                                <input type="submit" class="btn btn-lg btn-block" value="注册" />
	                            </fieldset>
	                            
                       		</form>
							 <div class="row text-center">
						        <hr />
						        <p>已是代理 <a href="login.html" style="font-weight:bold;color: #222;">直接登录</a></p>
						        <!--<p><a href="">忘记密码，联系管理员重置密码</a></p>-->
						    </div>
						</div>
				</div>

			</div>
		</div>
	</div>
	<script type="text/javascript">
		$(function () {
		    var reg_level = "{$reg_level}";
		    if(reg_level == 1) {
		        $("#showRules").attr('data-content',"<p>注册时没填写推荐码，则默认成为一级代理；</p><p>注册时填写了推荐码，则成为推荐人的下级代理；</p><p>注册成为代理后需要通过管理审核后才能登录。</p>")
			}else if(reg_level == 3) {
		        $("#showRules").attr("data-content","<h3>代理注册</h3><p>注册时没填写推荐码，则默认成为三级代理；</p><p>注册时填写了推荐码，则成为推荐人的下级代理；</p><p>注册成为代理后需要通过管理审核后才能登录。</p><h3>返利提现</h3><p> 下级会员或代理购买房卡后，上级代理将获得一定比例返利</p><p>返利收益达到100元可以申请提现</p><p>周六周末不可申请提款</p><p>提款时间为上午10:00-22:00</p><p>可以选择提款到微信或支付宝</p><p>微信支付宝请提前和客服沟通</p>")
			}
			var values = $("#refer").attr('placeholder');
			if($.trim(values) == '' || $.trim(values) == 'GAME_LOGIN_REFER') {
			    $("#refer").parent("div").hide();
			}
        })
		$("#showRules").popover();
		$("#user_id").blur(function(){
			var url = "{:U('Admin/Login/checkUserId')}";
			var user_id = $.trim($("#user_id").val());
			if(user_id != "") {
				$.ajax({
					type:"post",
					url:url,
					dataType:"json",
					data:{"user_id":user_id},
					success:function(data) {
						if(data == "unexist") {
							alert("抱歉,该游戏UID不存在或者已经注册成为代理了,不能注册！");
							$("#user_id").val('');
							return false;
						}else{
                            $.ajax({
                                type:'get',
                                url:"{:U('Admin/Login/checkUserIdSql')}?user_id="+user_id,
                                success:function(res) {
                                    if(res == 'uexist') {
                                        alert("该游戏UID已申请代理了!");
                                        $("#user_id").val('');
                                        return false;
                                    }
                                }
                            });
						}
					}
				});

			}
		});
	
		$("#tel").blur(function(){
			var url = "{:U('Admin/Login/checkTel')}";
			var tel = $.trim($("#tel").val());
			if(tel != "") {
				$.ajax({
					type:"post",
					url:url,
					dataType:"json",
					data:{"tel":tel},
					success:function(data){
						if(data == "texist"){
							alert("抱歉，该手机号已被注册！");
                            $("#tel").val('');
							return false;
						}
					}
				});
			}
		});
	
		$.validator.setDefaults({
			submitHandler:function() {
				var tel = $.trim($("#tel").val());
				var params = $("input").serialize();
				var url = "{:U('Admin/Login/regSave')}";
				$.ajax({
					type:"post",
					url:url,
					timeout:5000,  //超时时间设置，单位毫秒
					dataType:"json",
					data:params,
					success: function(data){
						if (data=='exist') {
	                    	alert("抱歉，该账号已被注册！");
	                        return false;
	                    }else if (data=='noRefer') {
							alert("抱歉，该推荐码无效！");
	                        return false;
	                    }else if (data=='success') {
	                        alert('注册成功!');
	                        localStorage.setItem("tel",tel);
	                        window.location.href="{:U('Admin/Login/infoSave')}";
	                    }else if(data == 'unexist'){
	                    	alert("该游戏UID不存在，不能注册！");
							return false;
	                    }else if (data=='error'){
	                        alert('注册失败！');
	                        window.location.href="{:U('Admin/Login/register')}";
	                    }
					},
					complete:function(XMLHttpRequest,status){
						if(status == "timeout"){
							alert("请求超时");
						}
					}
				});
				
			}
		});
		
		$().ready(function(){
			$("#signupForm").validate({
				rules: {
			      tel: "required",
			      password:"required",
			      user_id:"required",
			      tel: {
			        required: true,
					isMobile:true,
			      },
			      password: {
			        required: true,
			        minlength: 6,
			        maxlength: 20
			      },
			      user_id: {
			      	required:true,
			      	minlength: 6
			      }
			  },
			  messages: {
			  	tel: "请输入您的手机号码",
			  	password: "请输入您的密码",
			  	user_id: "请输入您的游戏ID",
			  	tel: {
			  		required: "请输入手机号码",
                    isMobile:"请输入正确的手机号码"
			  	},
			  	password: {
			  		required: "请输入密码",
			  		minlength: "密码最少是6位",
			  		maxlength: "密码最多20位"
			  	},
			  	user_id: {
			  		required: "游戏ID是必填项",
			  		minlength: "游戏ID最少6位数",
			  		maxlength: "游戏ID最多6位数",
		  		}
			  }
			});
		})
	</script>
	</body>
</html>
